package com.minimalist.lindi.controller;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.indexchangerecord.LindiIndexChangeRecordQueryVO;
import com.minimalist.common.entity.lindi.vo.indexchangerecord.LindiIndexChangeRecordVO;
import com.minimalist.common.response.R;
import com.minimalist.common.utils.Add;
import com.minimalist.common.utils.Update;
import com.minimalist.lindi.service.LindiIndexChangeRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 11987
 */
@Validated
@RestController
@Tag(name = "林地指标交易平台_指标变更记录管理")
@RequestMapping("/lindi/indexChangeRecord")
public class LindiIndexChangeRecordController{

    @Autowired
    private LindiIndexChangeRecordService service;

    @PostMapping("/addIndexChangeRecord")
    @Operation(summary = "添加指标变更记录")
    public R<?> addIndexChangeRecord(
            @RequestBody @Validated(Add.class)
            LindiIndexChangeRecordVO recordVO){
        service.addIndexChangeRecord(recordVO);
        return R.ok();
    }

    @DeleteMapping("/deleteIndexChangeRecordByIndexChangeRecordId")
    @Operation(summary = "删除指标变更记录 -> 根据记录ID删除")
    public R<?> deleteIndexChangeRecordByIndexChangeRecordId(
            @RequestParam("indexChangeRecordId")
            @NotNull(message = "记录ID不能为空")
            @Parameter(name = "recordId", required = true, description = "记录ID")
            Long indexChangeRecordId){
        service.deleteIndexChangeRecordByIndexChangeRecordId(indexChangeRecordId);
        return R.ok();
    }

    @PutMapping("/updateIndexChangeRecordByIndexChangeRecordId")
    @Operation(summary = "修改指标变更记录")
    public R<?> updateIndexChangeRecordByIndexChangeRecordId(
            @RequestBody @Validated(Update.class) LindiIndexChangeRecordVO recordVO){
        service.updateIndexChangeRecordByIndexChangeRecordId(recordVO);
        return R.ok();
    }

    @GetMapping("/getPageIndexChangeRecordList")
    @Operation(summary = "查询指标变更记录列表(分页)")
    public R<PageResp<LindiIndexChangeRecordVO>> getPageIndexChangeRecordList(
            LindiIndexChangeRecordQueryVO queryVO){
        return R.ok(service.getPageIndexChangeRecordList(queryVO));
    }

    @GetMapping("/getIndexChangeRecordByIndexChangeRecordId/{indexChangeRecordId}")
    @Operation(summary = "根据记录ID查询指标变更记录")
    public R<LindiIndexChangeRecordVO> getRecordByRecordId(
            @PathVariable(value = "indexChangeRecordId")
            @NotNull(message = "记录ID不能为空")
            @Parameter(name = "indexChangeRecordId", description = "记录ID", required = true)
            Long indexChangeRecordId){
        return R.ok(service.getIndexChangeRecordByIndexChangeRecordId(indexChangeRecordId));
    }
}